#ifndef GRAPH_H
#define GRAPH_H

#include <QWidget>
#include <QPainter>
#include <QtCore>
#include <QString>
#include <QHash>
#include <QApplication>
#include <QDesktopWidget>
#include "stock.h"
#include "predictor.h"
#include "regressionanalysis.h"

namespace Ui {
    class graph;
}

class graph : public QWidget
{
    Q_OBJECT

public:
    QHash<QString, Stock*> cache;
    static const QString googleStockCode;
    static const QString googleDataFile;
    static const QString microsoftStockCode;
    static const QString microsoftDataFile;
    static const QString appleStockCode;
    static const QString appleDataFile;
    explicit graph(QWidget *parent = 0);
    void paintEvent(QPaintEvent*);
    void paintEngine();
    void destroy(bool destroyWindow, bool destroySubWindows);
    void closeEvent(QCloseEvent *);
    void setStockData(Stock *stock);
    void setStockCode(QString string);
    void setPredictor(Predictor *p);
    void setPredictionTimer(QString number);
    void startPredictionTimer();
    void setConnectionOfTimer();
    Predictor* getPredictor();
    ~graph();

private slots:
    void myChoiceChanged(QString string);
    void spinnerBoxValueChanged(QString number);
    void predictionData(QHash<QString, QString> dataPredicted);
    void spinnerBoxGoogleChanged(int);
    void spinnerBoxAppleChanged(int);
    void spinnerBoxMicrosoftChanged(int);
    void labelClick(bool);
    void portfolioClick(bool);
    void showStock(bool);
    void showPortfolioData(bool);

signals:
    void stockValueChanged(QString string);
private:
    Ui::graph *ui;

    Predictor *predictor;
    QString stockCode;
    QString predictorStockCode;
    QString pColor;
    Stock *stockData;
    QTimer *timer;
    static const int interval = 15*60; //interval for xlabel is 15 mins
    static const int spaceBetweenLabels = 50;
    static const int startOfYaxis = 30;
    qint16 endOfYaxis;
    QString predictionTimer;
    QString getPredictionTimer();
};


#endif // GRAPH_H
